package com.zhijian.medical.util;

public class ConvertCode {



    /**

     * @Title:bytes2HexString

     * @Description:字节数组转16进制字符串

     * @param b

     * 字节数组

     * @return 16进制字符串

     * @throws

     */

    public static String bytes2HexString(byte[] b) {

        StringBuffer result = new StringBuffer();

        String hex;

        for (int i = 0; i < b.length; i++) {

                hex = Integer.toHexString(b[i] & 0xFF);

            if (hex.length() == 1) {

                    hex = '0' + hex;

            }

            result.append(hex.toUpperCase());

        }

        return result.toString();

    }

    /**

     * @Title:hexString2Bytes

     * @Description:16进制字符串转字节数组

     * @param src 16进制字符串

     * @return 字节数组

     */

    public static byte[] hexString2Bytes(String src) {

        int l = src.length() / 2;

        byte[] ret = new byte[l];

        for (int i = 0; i < l; i++) {

            ret[i] = (byte) Integer.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();

        }

        return ret;

    }
}
